<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 10%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/lang/zh-cn/zh-cn.js"></script>
    <form class="layui-form layui-form-pane1" method="post" enctype="multipart/form-data">
        <input type="hidden" value="<?php echo $result['id'];?>" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">列表标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="{$result['title']}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">主标题</label>
            <div class="layui-input-block">
                <input type="text" name="main_title" value="{$result['main_title']}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公告内容</label>
            <div class="layui-input-block">
                <script name="content" id="editor" type="text/plain" style="width:960px;height:300px;">{$result['content']}</script>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否置顶</label>
            <div class="layui-input-block">
                <input type="radio" name="is_top" value="0" title="否" <if $result['is_top']==0> checked="checked" </if>>
                <input type="radio" name="is_top" value="1" title="是" <if $result['is_top']==1> checked="checked" </if>>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">目标用户</label>
            <div class="layui-input-block">

                <text class="panduan1">  <input type="checkbox" value="1" name="target[]" lay-filter="target3"  class="target1" <if strstr($result['target'],"1")> checked="checked" </if> title="已认证" <if strstr($result['target'],"4")> disabled="disabled" </if>></text>
                <text class="panduan2">
                <input type="checkbox" value="4" class="target"  lay-filter="tdyh" <if strstr($result['target'],"4")> checked="checked" </if> name="target[]" title="特定用户" <if strstr($result['target'],"1")> disabled="disabled" </if>>
                </text>
            </div>
        </div>
        <div class="layui-form-item inputModel phone" <if strstr($result['target'],"1")> style="display: none" </if>>
        <label class="layui-form-label">补发手机号码(,[逗号]分割)</label>
            <div class="layui-input-block">
                    <textarea name="phonearea" id="" cols="30" rows="10" class="textarea">{$phone}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">司机类型</label>
            <div class="layui-input-block">
                <input type="checkbox" value="1" name="driver_type[]" title="快车" <if strstr($result['driver_type'],"1")> checked="checked" </if>>
                <input type="checkbox" value="2" name="driver_type[]" title="城际" <if strstr($result['driver_type'],"2")> checked="checked" </if>>
            </div>
        </div>
        <if strstr($result['driver_type'],"4")>
        <div class="layui-form-item inputModel">
            <label class="layui-form-label">driver_id</label>
            <div class="layui-input-block">
                <textarea  class="layui-textarea"  name="uids"><?php echo $result['uids']; ?></textarea>
            </div>
        </div>
        </if>
        <div class="layui-form-item">
            <label class="layui-form-label">城市选择</label>
            <div class="layui-input-block">
                <select name="cs_type" class="select class-select"  lay-filter="cs_type" id="cs_type">
                    <option value="0" <if $result['citys']=='0'>selected</if> >全国</option>
                    <option value="1" <if $result['citys']!='0'> selected </if> >选择省市</option>
                </select>
            </div>
        </div>
        <table class="layui-table">
            <tr class="province01" <if $result['citys']=='0'> style="display:none" </if>>
                <td>省级区域</td>
                <td>
                    <input type="checkbox" value="all" title="全部" class="province_all pro" lay-filter="province"  >
                    <volist name="provinces" id="province">
                        <input type="checkbox" name="region[2][]" title="{$province}" value="{$key}"
                               class="lay-input province_child province pro" lay-filter="province" {$config['edit_provinces'][$key]?"checked='checked'":""}>
                    </volist>
                </td>
            </tr>
            <tr class="city01" <if $result['citys']=='0'> style="display:none" </if>>
                <td>市级区域</td>
                <td>
                    <ul id="city">
                        <volist name="config['edit_provinces']" id="edit_pro">
                            <php>$pid = $key; $class = 'city_'.$pid;</php>
                            <li class="{$class} region_li">
                                <input type="checkbox" value="all" data-pid="{$pid}" title="{$edit_pro}"
                                       class="lay-input city_all_{$pid}"  {$city_all[$pid]?'checked':''}>
                                <volist  name="$config['edit_citys'][$pid]" id="city">
                                    <input type="checkbox" name="region[3][{$pid}][]" data-pid="{$pid}" title="{$city}" value="{$key}"
                                           class="lay-input city_child_{$pid} city"
                                    <if condition="in_array($key,$info['region'][3][$pid])">checked</if> >
                                </volist>
                            </li>
                        </volist>
                    </ul>
                </td>
            </tr>
            <div class="layui-form-item">
                <label class="layui-form-label">发布时间</label>
                <div class="layui-input-block">
                    <input type="radio" name="time" value="0" title="实时"  checked>
                    <input type="radio" name="time" value="1" title="定时">
                    <div class="layui-inline">
                        <input type="text" value="{:date('Y-m-d H:i:s',$result['add_time'])}" class="layui-input" name="add_time" id="add_time" placeholder="发布开始时间">
                    </div>
                </div>
            </div>
            <tr>
                <td colspan="3" style="padding-left: 100px;">
                    <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </td>
            </tr>
        </table>
    </form>
    <script>
        layui.use(['form', 'upload', 'laydate'], function () {

            form = layui.form, upload = layui.upload;
            level = 3,pro_tmp = [], cit_tmp =[],cou_tmp =[];

            $('.province').each(function () {
                if($(this).prop('checked')){
                    pro_tmp.push($(this).val());
                }
            });
            $('.city').each(function () {
                if($(this).prop('checked')){
                    cit_tmp.push($(this).val());
                }
            });
            var laydate = layui.laydate;
            laydate.render({
                elem: '#add_time' //指定元素
                ,type: 'datetime'
            });

            upload.render({
                elem: '.uploads'//这个就等同于点击
                , url: '/admin/Upload/uploadImg'
                , done: function (res) { //上传后的回调
                    console.log(res)
                    if (res.status == 1) {
                        $("#pic_url").css('display', '');
                        $("#pic_url").attr('src', res.data.file); //点击后的大图
                        $("#pic_url").attr('layer-src', res.data.file_thumb); //小图
                        $("#activity_img").val(res.data.file); //点击后的大图
                        layer.msg('上传成功', {icon: 1});
                    } else {
                        layer.msg(res.msg);
                    }
                }
                , error: function (e) {
                    console.log(e)
                }
            });
            $(".panduan1").on('click',function (data) {
                console.log($('.target1'))
                console.log($(".target1").prop("disabled"))
                if($(".target1").prop("disabled") == true){
                    layer.msg("请先取消特定用户");
                }

            })
            $(".panduan2").on('click',function (data) {
                console.log(222)
                console.log($('.target'))
                if($(".target").prop("disabled") == true){
                    layer.msg("请先取消已认证");
                }
            })

            form.on('checkbox(tdyh)',function (data) {
                $('.phone').show();
                $(".target1").attr('disabled',true)
                var elem = data.elem;
                var check = elem.checked;
                if (!check){
                    $('.phone').css({display:"none"});
                    $(".target1").attr('disabled',false)
                }
            });


            form.on('checkbox(target3)',function (data) {
                $(".target").attr('disabled',true)
                var elem = data.elem;
                var check = elem.checked;
                if (!check){
                    $(".target").attr('disabled',false)
                }
            });
            form.on('select(cs_type)',function (data) {
                console.log(data)
                if (data.value==1){
                    $('.province01').show();
                    $('.city01').show();
                }else {
                    $('.province01').css('display','none');
                    $('.city01').css('display','none');
                }

            });
            form.on('submit(*)', function (data) {
                //活动时间比较
                var start_time = $("#start_time").val();
                var end_time = $("#end_time").val();
                if (start_time > end_time) {
                    layer.msg('活动开始时间不能大于结束时间', {icon: 5});
                    return false
                }
                var user_type = $("#user_type").val();
                var activity_model = $("#activity_model").val();
                if (user_type == 2) {
                    if (activity_model == 7 || activity_model == 8) {
                        var start_time_interval = $("#start_time_interval").val();
                        var end_time_interval = $("#end_time_interval").val();
                        var st = start_time_interval.split(':');
                        var et = end_time_interval.split(':');
                        if ((st[0] + st[1]) * 1 > (et[0] + et[1]) * 1) {
                            layer.msg('活动时间段时间不能大于结束时间', {icon: 5});
                            return false
                        }
                    } else if (activity_model == 2) {
                        var order_start_time_interval = $("#order_start_time_interval").val();
                        var order_end_time_interval = $("#order_end_time_interval").val();
                        var st = order_start_time_interval.split(':');
                        var et = order_end_time_interval.split(':');
                        if ((st[0] + st[1]) * 1 > (et[0] + et[1]) * 1) {
                            layer.msg('活动时间段时间不能大于结束时间', {icon: 5});
                            return false
                        }
                    }
                }

            });


            form.on('checkbox(province)',function (data) {
                $('.city01').show();
                var elem = data.elem,value = data.value,check = elem.checked,all = $('.province_all'),
                    item = $('.province_child'),index = 0,flag = false,pro = [];
                console.log(check)
                switch (value) {
                    case 'all':
                        item.each(function () {
                            $(this).prop({'checked': check});
                            var ind = pro_tmp.indexOf($(this).val());
                            if(ind==-1){
                                pro.push($(this).val());
                                pro_tmp.push($(this).val());
                            }
                        });
                        if(!check){
                            pro=[];pro_tmp=[];
                            $('#city').html('');
                            $('#county').html('');
                            $('#city_').hide();
                            $('#county_').hide();
                        }
                        break;
                    default:
                        item.each(function () {
                            if ($(this).prop('checked')) {
                                index++;
                            }
                        });
                        if (index == item.length) {
                            flag = true;
                        }
                        all.prop({'checked': flag});
                        if(!check){
                            var ind = pro_tmp.indexOf(value);
                            if(ind>-1){
                                pro_tmp.splice(ind,1);
                            }
                            console.log(value)
                            $('._'+value).remove();
                            if($('#city').children('li').length==0){
                                $('#city_').hide();
                            }
                            if($('#county').children('li').length==0){
                                $('#county_').hide();
                            }
                        }else{
                            pro = [];pro.push(value);pro_tmp.push(value);
                        }
                        break;
                }
                form.render('checkbox');
                if(pro.length > 0 && level > 2 ){
                    ajax(form,layer,pro,2,'city');
                }
            });
            form.on('checkbox(city)',function (data) {
                var admin_type = $("#admin_type").val();
                if(admin_type == 4){
                    $('.county01').show();
                }
                var elem = data.elem, value = data.value,check = elem.checked,all = $('.city_all_'+$(elem).data('pid')),
                    item = $('.city_child_'+$(elem).data('pid')),index = 0,flag = false,cit = [];
                switch (value) {
                    case 'all':
                        item.each(function () {
                            $(this).prop({'checked': check});
                            var ind = cit_tmp.indexOf($(this).val());
                            if(ind==-1){
                                cit.push($(this).val());
                                cit_tmp.push($(this).val());
                            }
                        });
                        if(!check){
                            cit=[];cit_tmp=[];
                            $('#county').html('');
                            $('#county_').hide();
                        }
                        form.render('checkbox');
                        break;
                    default:
                        item.each(function () {
                            if ($(this).prop('checked')) {
                                index++;
                            }
                        });
                        if (index == item.length) {
                            flag = true;
                        }
                        if(!check){
                            var ind = cit_tmp.indexOf(value);
                            if(ind>-1){
                                cit_tmp.splice(ind,1);
                            }
                            $('.county_'+value).remove();
                            if($('#county').children('li').length==0){
                                $('#county_').hide();
                            }
                        }
                        else{
                            cit = [];cit.push(value);cit_tmp.push(value);
                        }
                        all.prop({'checked': flag});
                        form.render('checkbox');
                }
                if(cit.length > 0 && level == 4){
                    ajax(form,layer,cit,3,'county');
                }
            });
            form.on('checkbox(county)',function (data) {
                var elem = data.elem, value = data.value,check = elem.checked,all = $('.county_all_'+$(elem).data('pid')),
                    item = $('.county_child_'+$(elem).data('pid')),index = 0,flag = false;
                switch (value) {
                    case 'all':
                        item.each(function () {
                            $(this).prop({'checked': check});
                            var ind = cou_tmp.indexOf($(this).val());
                            if(ind==-1){
                                cou_tmp.push($(this).val());
                            }
                        });
                        if(!check){
                            cit_tmp=[];
                        }
                        form.render('checkbox');
                        break;
                    default:
                        item.each(function () {
                            if ($(this).prop('checked')) {
                                index++;
                            }
                        });
                        if (index == item.length) {
                            flag = true;
                        }
                        if(!check){
                            var ind = cou_tmp.indexOf(value);
                            if(ind>-1){
                                cou_tmp.splice(ind,1);
                            }
                        }
                        else{
                            cou_tmp.push(value);
                        }
                        all.prop({'checked': flag});
                        form.render('checkbox');
                }
            });
        });

        //验证只能输入数字
        function num(object) {
            var value = object.value;
            var id = object.id;
            if (isNaN(value)) {
                layer.msg('请输入正确的数字', {icon: 5});
                $("#" + id).val('');
                return false;
            }
        }


        function ajax(form,layer,pid,level,id) {
            $.post('{$url}',{pid:pid.join(','),level:level},function (res) {
                switch (res['status']){
                    case 1:
                        $('#'+id).append(res['html']);
                        form.render('checkbox');
                        $('#'+id+'_').show();
                        break;
                    default:
                        layer.alert(res['msg'],{icon:5});
                        break;
                }
            },'json')
        }


        //订单奖励 减少
        function reduceInsidePrice($this) {
            $($this).parent().parent().remove();
        }
    </script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
        var ue = UE.getEditor('editor',{
            zIndex : 0,// z轴
        });
    </script>
</block>
